<template>
  <div v-loading="listLoading"
       element-loading-text="数据加载中...">
    <div style="width: 100%;justify-content: flex-end;margin-bottom: 10px" class="flex-row">
      <slot name="leftTopMenu"></slot>
      <el-button type="primary" v-if="rightTableSetting.add.add"
                 v-hasPermi="[rightTableSetting.add.authorityName]"
                 @click="addItem('',false)"><i class="el-icon-plus" style="margin-right: 5px"></i>{{rightTableSetting.add.title}}</el-button>
      <slot name="exportDownload"></slot>
      <el-button type="primary"
                 v-if="rightTableSetting.importData.importData"
                 v-hasPermi="[rightTableSetting.importData.authorityName]"
      @click="downLoadTemp"><i class="el-icon-download" style="margin-right: 5px"></i>模板下载</el-button>
      <el-upload
        v-if="rightTableSetting.importData.importData"
        v-hasPermi="[rightTableSetting.importData.authorityName]"
        class="upload-demo"
        :action="fileUrl + tableOptions.importUrl"
        :data="{tableName:tableName}"
        :show-file-list="false"
        :headers="{Authorization:'Bearer ' + getAdminToken()}"
        style="margin:0 10px"
        :before-upload="deforeUpload"
        :on-success="uploadSuccess"
        :on-error="uploadError"
      >
        <el-button type="primary"><i class="el-icon-upload" style="margin-right: 5px"></i>{{rightTableSetting.importData.title}}</el-button>
      </el-upload>
      <!--      <el-button type="primary" v-if="rightTableSetting.importData.importData"-->
      <!--                 v-hasPermi="[rightTableSetting.importData.authorityName]" @click="importData">{{rightTableSetting.importData.title}}</el-button>-->
      <el-button type="primary" v-if="rightTableSetting.exportData.exportData"
                 v-hasPermi="[rightTableSetting.exportData.authorityName]" @click="exportDataAxios"><i class="el-icon-s-promotion" style="margin-right: 5px"></i>{{rightTableSetting.exportData.title}}</el-button>
      <el-button type="primary" v-if="rightTableSetting.deleteBatches.deleteBatches" @click="delDatas"
                 v-hasPermi="[rightTableSetting.deleteBatches.authorityName]" :disabled="!selectSelection.length">{{rightTableSetting.deleteBatches.title}}</el-button>
      <el-button type="primary" v-if="rightTableSetting.editBatches.editBatches"
                 v-hasPermi="[rightTableSetting.editBatches.authorityName]" :disabled="!selectSelection.length">{{rightTableSetting.editBatches.title}}</el-button>
      <slot name="rightTopMenu"></slot>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      @selection-change="selectionChange"
      @row-click="rowClick">
      <el-table-column
        type="selection"
        width="55"
        align="center"
        v-if="rightTableSetting.editBatches.editBatches || rightTableSetting.deleteBatches.deleteBatches">
      </el-table-column>
      <el-table-column
        type="index"
        :index="indexMethod"
        v-if="rightTableSetting.paginSetting"
        align="center"
        width="50px"
        label="序号">
      </el-table-column>
      <el-table-column
        v-for="item in setTableColumn"
        :align="item.alignment"
        :prop="item.tableName + '&' + item.field"
        :width="item.columnWidth == 100 ? 'auto' : item.columnWidth"
        :label="item.hasOwnProperty('customizeColumnName') && item.customizeColumnName ? item.customizeColumnName : item.columnName">
        <template  slot-scope="scope">
          <slot :name="item.tableName + '&' + item.field" :record="scope.row">
            <div>
              {{scope.row[item.tableName + '&' + item.field]}}
            </div>
          </slot>
        </template>
      </el-table-column>
      <el-table-column v-if="rightTableSetting.edit.edit || rightTableSetting.deleteRow.deleteRow" prop="handle" label="操作" align="center" width="200px">
        <template slot-scope="scope">
          <div v-if="!rowBtnList.length">
            <el-button type="text" v-if="rightTableSetting.edit.edit"
                       v-hasPermi="[rightTableSetting.edit.authorityName]"
                       @click.stop="addItem(scope.row,false)">{{rightTableSetting.edit.title}}</el-button>
            <el-button type="text" v-if="rightTableSetting.deleteRow.deleteRow"
                       v-hasPermi="[rightTableSetting.deleteRow.authorityName]"
                       @click.stop="delItem(scope.row)">{{rightTableSetting.deleteRow.title}}</el-button>
          </div>
          <div v-else>
            <el-popover
              placement="bottom"
              width="200"
              trigger="hover"
            >
              <template #reference>
                <div style="color: #1890FF;font-size: 16px">
                  <i class="iconfont icon-sangedian"></i>
                </div>
              </template>

              <div style="width: 100%;align-items: center" class="flex-row-column">
                <el-button type="text" v-if="rightTableSetting.edit.edit"
                           v-hasPermi="[rightTableSetting.edit.authorityName]"
                           @click.stop="addItem(scope.row,false)"
                >{{rightTableSetting.edit.title}}</el-button>
                <div style="border: 1px solid #1890FF;width: 100%;" v-hasPermi="[rightTableSetting.edit.authorityName]"></div>
                <el-button type="text" v-if="rightTableSetting.deleteRow.deleteRow"
                           v-hasPermi="[rightTableSetting.deleteRow.authorityName]"
                           @click.stop="delItem(scope.row)"
                >{{rightTableSetting.deleteRow.title}}</el-button>
                <div style="border: 1px solid #1890FF;width: 100%;" v-hasPermi="[rightTableSetting.deleteRow.authorityName]"></div>
                <div v-for="(item,index) in rowBtnList" :key="item.authorityName" style="width: 100%;align-items: center" class="flex-row-column">
                  <el-button type="text" v-if="btnShow(item,scope.row)"
                             v-hasPermi="[item.authorityName]"
                             @click.stop="branchFormDialog(item,scope.row)">{{item.title}}</el-button>
                  <div style="border: 1px solid #1890FF;width: 100%;" v-if="(rowBtnList.length - 1) != index && btnShow(item,scope.row)" v-hasPermi="[item.authorityName]"></div>
                </div>
              </div>
            </el-popover>
          </div>
        </template>

      </el-table-column>
    </el-table>

    <div style="height: 20px"></div>
    <div v-if="rightTableSetting.paginSetting" style="display: flex; justify-content: center">
      <el-pagination
        background
        layout="sizes,prev,pager,next,jumper,total"
        :page-size="paging.pageSize"
        :page-sizes="[5,10, 20, 30, 40, 50, 100]"
        :total="paging.total"
        @size-change="changeSize"
        @current-change="changeCurrent"
      />
    </div>

    <div style="width: 100%;overflow: hidden" v-loading="formLoading" v-if="this.formConfig.hasOwnProperty('popUpMode') && this.formConfig.popUpMode == '正常布局'">
      <transition name="fade-transform" mode="out-in">
        <div v-if="showInput" style="width: 100%;overflow: hidden;transition:0.5s;position: relative">
          <tip-title title="表单信息"></tip-title>
          <v-form-render :form-data="formData" ref="vFormCurrentRowRef"></v-form-render>
          <slot name="bottomForm" :formData="formJsonParse"></slot>
          <div style="height: 42px"></div>
          <div style="position: fixed;width: 100%;height:42px;background: #fff;z-index: 100;bottom: 0;">
            <div style="width: 100%;display: flex;justify-content: center;align-items: center;
position: relative;left: -6%;">
              <el-button type="primary" @click="saveForm" v-if="!disabledVal">保存</el-button>
              <el-button @click="showInput = false" v-if="!disabledVal">取消</el-button>
            </div>
          </div>
        </div>
      </transition>
    </div>

    <el-dialog-comp :title="dialogTitle" width="40%" :hasFooter="true" :appendToBody="true" ref="refDialog"
                    @throwDialogEmit="submitDialog">
      <v-form-render ref="vFormDialogRowRef"></v-form-render>
    </el-dialog-comp>
    <el-drawer-comp :headTitle="drawerTitle" size="80%" :hasFooter="true" :destroyOnClose="true" :appendToBody="true" ref="refDrawer"
                    @throwSumitEmit="submitDrawer">
      <v-form-render ref="vFormDrawerRowRef"></v-form-render>
    </el-drawer-comp>


    <el-dialog-comp :title="dialogTitle" :width="this.formConfig.dialogWidth + '%'" :hasFooter="disabledVal ? false : true" :appendToBody="true" ref="refDialog1"
                    @throwDialogEmit="saveForm">
      <v-form-render ref="dialogRowRef"></v-form-render>
      <slot name="bottomForm"></slot>
    </el-dialog-comp>
    <el-drawer-comp :headTitle="drawerTitle" :size="this.formConfig.drawerWidth + '%'" :hasFooter="disabledVal ? false : true" :destroyOnClose="true" :appendToBody="true" ref="refDrawer1"
                    @throwSumitEmit="saveForm" :direction="this.formConfig.drawerPop">
      <div style="width: 100%;height: 100%;padding: 20px;box-sizing: border-box">
        <v-form-render ref="drawerRowRef"></v-form-render>
        <slot name="bottomForm"></slot>
      </div>
    </el-drawer-comp>
  </div>
</template>

<script>
/**
 * @param customForm true false 自定义新增表单
 * @param formMethod @function 自定义表单需要执行得函数
 * */
import {
  getJSONForm,
  getList,
  onlineAdd,
  onlineDel,
  onlineEdit,
  onlineList,
  viewTable,
  chaEditView,
  getDels, exportDataList,downGeneralTemp
} from '@/api/public'
import {listMenu} from "@/api/system/menu";
import { parse } from 'html-to-ast'
import { exportLocationExcel } from '@/utils'
import {mapGetters} from 'vuex'
import {getToken} from '@/utils/auth'

export default {
  name: "TableColumn",
  props:{
    yuanSetTableData:{
      type:Array,
      default(){
        return []
      }
    },
    rightTableSetting:{
      type:Object,
      default() {
        return {};
      }
    },
    tableOptions:{
      type:Object,
      default() {
        return {};
      }
    },
  },
  data(){
    return {
      fileUrl:process.env.VUE_APP_BASE_API,
      tableData:[],
      setTableColumn:[],
      formConfig:{},
      paging:{
        total:0,
        currentPage:1,
        pageSize:10
      },
      dialogTitle:'',
      drawerTitle:'',
      formData:{},
      showInput:false,
      disabledVal:false,
      formLoading:false,
      saveType:0,
      saveId:'',
      searchParams:{},
      rowBtnList:[],
      formDesign:'',
      tableName:'',
      listLoading:false,
      formJsonParse:{},
      selectSelection:[],
      scopeData:{},
      throwFormJson:{}
    }
  },
  computed:{
    ...mapGetters(['userId'])
  },
  watch:{
    'yuanSetTableData':{
      handler(val){
        if(val && val.length){
          this.setTableColumn = val.filter(item => item.showColumn == true)
        }
        else{
          this.setTableColumn = []
        }

      },
      immediate:true
    },
    rightTableSetting:{
      handler(val){
        this.rowBtnList = val.rowBtnList || []
      },
      immediate:true
    }
  },
  created() {
    this.paging.currentPage = 1
    listMenu().then(res => {
      if(res.data && res.data.length){
        const ind = res.data.findIndex(item => {
          return item.menuName == this.$route.meta.title
        })
        this.tableName = res.data[ind].path
        console.log(this.tableName,'this.tableName')
        this.getTableList()
        getList({tableName:this.tableName}).then(result1 => {
          if(result1.data.records && result1.data.records.length){
            getJSONForm({onlineTableId:result1.data.records[0].id}).then(result => {
              console.log(result,'result-result')
              if(result.data.records && result.data.records.length){
                if(result.data.records && result.data.records.length){
                  this.formJsonParse = {
                    ...JSON.parse(result.data.records[0].widgetJson).formConfig,
                    ...JSON.parse(result.data.records[0].widgetJson)
                  }
                  this.$nextTick(()=> { //设置表单
                    this.formConfig = {
                      ...JSON.parse(result.data.records[0].widgetJson).formConfig
                    }
                    this.throwFormJson = JSON.parse(result.data.records[0].widgetJson)
                  })
                }
              }
            })
          }
        })
      }
    })

  },
  methods:{
    indexMethod(index){
      return (this.paging.currentPage - 1) * this.paging.pageSize + index + 1
    },
    changeSize(val){
      this.paging.pageSize = val
      this.getTableList()
    },
    changeCurrent(val){
      this.paging.currentPage = val
      this.getTableList()
    },
    rowClick(row){
      this.addItem(row,true)
    },
    getSearchData(searchParams){ //列表搜索
      console.log(searchParams,'searchParams')
      this.paging.currentPage = 1
      for(let val of searchParams){
        if(Array.isArray(val.value)){
          if(val.value[0]){
            this.searchParams[val.type] = val.value.join(',')
          }
          else{
            this.searchParams[val.type] = null
          }
        }
        else this.searchParams[val.type] = val.value
        continue
      }
      this.getTableList()
    },
    clearSearchData(){ //列表清空
      this.paging.currentPage = 1
      this.searchParams = {}
      this.getTableList()
    },
    getTableList(){
      this.listLoading = true
      let extendStr = null
      if(this.$props.tableOptions.hasOwnProperty('extend') && this.$props.tableOptions.extend){
        extendStr = this.$props.tableOptions.extend.replace(/nameId/g,this.userId)
      }
      const params ={
        size:this.paging.pageSize,
        current:this.paging.currentPage,
        paramJson:JSON.stringify({
          tableName:this.$props.tableOptions.tableName || this.tableName,
          delFlag:this.$props.tableOptions.hasOwnProperty('delFlag') ? this.$props.tableOptions.delFlag : '0',
          ...this.searchParams,
          extend:extendStr
        })

      }
      onlineList(this.$props.tableOptions.listUrl,params).then(res => {
        if(res.code == 200){
          this.tableData = res.data.records
          this.paging.total = res.data.total * 1
          this.listLoading = false
        }
        else{
          this.tableData = []
          this.paging.total = 0
          this.listLoading = false
        }
      }).catch(()=>{
        this.listLoading = false
      })
    },

    addItem(item,bol){
      this.showInput = true
      let cloneItem = null
      this.listLoading = true
      try{
        if(item){
          cloneItem = {
            ...item
          }
          const keys = Object.keys(cloneItem)
          for(let key of keys){
            if(key.includes('&')){
              const cloneKey = key.split('&')[1]
              cloneItem[cloneKey] = cloneItem[key]
              delete cloneItem[key]
              continue
            }
          }

          chaEditView({
            tableName:this.$props.tableOptions.tableName,
            id:cloneItem.id
          }).then(results => {
            if(results.code == 200){
              getList({tableName:this.$props.tableOptions.tableName}).then(res => {
                if(res.data.records && res.data.records.length){
                  getJSONForm({onlineTableId:res.data.records[0].id}).then(result => {
                    if(result.data.records && result.data.records.length){
                      this.formJsonParse = {
                        ...JSON.parse(result.data.records[0].widgetJson).formConfig,
                        ...JSON.parse(result.data.records[0].widgetJson)
                      }
                      this.$nextTick(()=>{ //设置表单
                        this.formConfig = {
                          ...JSON.parse(result.data.records[0].widgetJson).formConfig
                        }
                        this.throwFormJson = JSON.parse(result.data.records[0].widgetJson)
                        // multiple
                        if(!this.formConfig.popUpMode || this.formConfig.popUpMode == '正常布局'){
                          if(this.$props.tableOptions.hasOwnProperty('arrayKey')){

                            for(let mutKey of this.$props.tableOptions.arrayKey){
                              results.data[mutKey] = results.data[mutKey] && results.data[mutKey].length ? results.data[mutKey].split(',') : []
                            }
                          }
                          cloneItem = {
                            ...results.data
                          }
                          if(cloneItem && bol){
                            this.disabledVal = true
                            this.saveType = 2
                            this.saveId = cloneItem.id
                            this.$nextTick(() => {
                              console.log(this.$refs.vFormCurrentRowRef,'this.$refs.vFormCurrentRowRef')
                              this.$refs.vFormCurrentRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                              // 表单禁用
                              setTimeout(()=>{
                                //设置数据并禁用
                                this.$refs.vFormCurrentRowRef.setFormData(cloneItem)
                                this.$refs.vFormCurrentRowRef.disableForm();
                              },500)
                            })
                          }
                          else if(cloneItem){
                            this.disabledVal = false
                            this.saveId = cloneItem.id
                            this.saveType = 1
                            this.$nextTick(()=>{
                              this.$refs.vFormCurrentRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                              setTimeout(()=>{
                                //设置数据
                                this.$refs.vFormCurrentRowRef.setFormData(cloneItem)
                              },500)
                            })

                          }
                        }
                        else if(this.formConfig.popUpMode == '对话框'){
                          this.$refs.refDialog1.throwOpenDialog()
                          this.$nextTick(()=>{
                            setTimeout(()=>{
                              if(this.$props.tableOptions.hasOwnProperty('arrayKey')){
                                for(let mutKey of this.$props.tableOptions.arrayKey){
                                  results.data[mutKey] = results.data[mutKey].split(',')
                                }
                              }
                              cloneItem = {
                                ...results.data
                              }
                              if(cloneItem && bol){
                                this.disabledVal = true
                                this.saveType = 2
                                this.saveId = cloneItem.id
                                this.$nextTick(() => {
                                  this.$refs.dialogRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                                  // 表单禁用
                                  setTimeout(()=>{
                                    //设置数据并禁用
                                    this.$refs.dialogRowRef.setFormData(cloneItem)
                                    this.$refs.dialogRowRef.disableForm();
                                    this.dialogTitle = '查看详情'
                                  },500)
                                })
                              }
                              else if(cloneItem){
                                this.disabledVal = false
                                this.saveId = cloneItem.id
                                this.saveType = 1
                                this.$nextTick(()=>{
                                  this.$refs.dialogRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                                  setTimeout(()=>{
                                    //设置数据
                                    this.$refs.dialogRowRef.setFormData(cloneItem)
                                    this.dialogTitle = '编辑信息'
                                  },500)
                                })

                              }
                            },200)
                          })
                        }
                        else if(this.formConfig.popUpMode == '抽屉'){
                          this.$refs.refDrawer1.openDrawer()
                          this.$nextTick(()=>{
                            setTimeout(()=>{
                              this.$refs.drawerRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                              if(this.$props.tableOptions.hasOwnProperty('arrayKey')){
                                for(let mutKey of this.$props.tableOptions.arrayKey){
                                  results.data[mutKey] = results.data[mutKey].split(',')
                                }
                              }
                              cloneItem = {
                                ...results.data
                              }
                              if(cloneItem && bol){
                                this.disabledVal = true
                                this.saveType = 2
                                this.saveId = cloneItem.id
                                this.$nextTick(() => {
                                  // 表单禁用
                                  this.$refs.drawerRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                                  setTimeout(()=>{
                                    //设置数据并禁用
                                    this.$refs.drawerRowRef.setFormData(cloneItem)
                                    this.$refs.drawerRowRef.disableForm();
                                    this.drawerTitle = '查看详情'
                                  },500)
                                })
                              }
                              else if(cloneItem){
                                this.disabledVal = false
                                this.saveId = cloneItem.id
                                this.saveType = 1
                                this.$nextTick(()=>{
                                  this.$refs.drawerRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                                  setTimeout(()=>{
                                    //设置数据
                                    this.$refs.drawerRowRef.setFormData(cloneItem)
                                    this.drawerTitle = '编辑信息'
                                  },500)
                                })

                              }
                            },200)
                          })
                        }
                        this.$emit('setForm',{...results.data},this.saveType)

                      })
                    }
                  })
                }
              })
            }
            else{
              this.$message.error(results.msg || '数据模型加载失败')
              this.listLoading = false
            }
          }).catch(()=>{
            this.listLoading = false
          })
        }
        else{
          this.$emit('clearForm')
          getList({tableName:this.$props.tableOptions.tableName}).then(res => {
            if(res.data.records && res.data.records.length){
              getJSONForm({onlineTableId:res.data.records[0].id}).then(result => {
                if(result.data.records && result.data.records.length){
                  this.$nextTick(()=>{ //设置表单
                    this.formJsonParse = {
                      ...JSON.parse(result.data.records[0].widgetJson).formConfig,
                      ...JSON.parse(result.data.records[0].widgetJson)
                    }
                    this.formConfig = {
                      ...JSON.parse(result.data.records[0].widgetJson).formConfig
                    }
                    this.throwFormJson = JSON.parse(result.data.records[0].widgetJson)
                    if(!this.formConfig.popUpMode || this.formConfig.popUpMode == '正常布局'){
                      this.disabledVal = false
                      this.saveType = 0
                      this.$nextTick(()=>{
                        //自定义表单逻辑
                        if(this.$props.tableOptions.hasOwnProperty('customForm')){
                          const formObj = this.$props.tableOptions.formMethod(JSON.parse(result.data.records[0].widgetJson))
                          this.$refs.vFormCurrentRowRef.setFormJson(formObj)
                          //设置清空
                          this.$refs.vFormCurrentRowRef.resetForm();
                        }
                        else{
                          this.$refs.vFormCurrentRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                          //设置清空
                          this.$refs.vFormCurrentRowRef.resetForm();
                        }
                      })
                    }
                    else if(this.formConfig.popUpMode == '对话框'){
                      this.$refs.refDialog1.throwOpenDialog()
                      this.$nextTick(()=>{
                        setTimeout(()=>{
                          this.disabledVal = false
                          this.saveType = 0
                          this.dialogTitle = '新增信息'
                          this.$nextTick(()=>{
                            if(this.$props.tableOptions.hasOwnProperty('customForm')){
                              const formObj = this.$props.tableOptions.formMethod(JSON.parse(result.data.records[0].widgetJson))
                              this.$refs.dialogRowRef.setFormJson(formObj)
                              //设置清空
                              this.$refs.dialogRowRef.resetForm();
                            }
                            else{
                              this.$refs.dialogRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                              //设置清空
                              this.$refs.dialogRowRef.resetForm();
                            }

                          })
                        },200)
                      })
                    }
                    else if(this.formConfig.popUpMode == '抽屉'){
                      this.$refs.refDrawer1.openDrawer()
                      this.drawerTitle = '新增信息'
                      this.$nextTick(()=>{
                        setTimeout(()=>{

                          this.disabledVal = false
                          this.saveType = 0
                          this.$nextTick(()=>{
                            if(this.$props.tableOptions.hasOwnProperty('customForm')){
                              const formObj = this.$props.tableOptions.formMethod(JSON.parse(result.data.records[0].widgetJson))
                              this.$refs.drawerRowRef.setFormJson(formObj)
                              //设置清空
                              this.$refs.drawerRowRef.resetForm();
                            }
                            else{
                              this.$refs.drawerRowRef.setFormJson(JSON.parse(result.data.records[0].widgetJson))
                              //设置清空
                              this.$refs.drawerRowRef.resetForm();
                            }

                          })
                        },200)
                      })
                    }
                  })
                }
              })
            }
          })
        }
      }
      finally {
        this.listLoading = false
      }



    },
    delItem(row){
      let cloneItem = {
        ...row
      }
      const keys = Object.keys(cloneItem)
      for (let key of keys) {
        if (key.includes('&')) {
          const cloneKey = key.split('&')[1]
          cloneItem[cloneKey] = cloneItem[key]
          delete cloneItem[key]
          continue
        }
      }
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = {
          tableName:this.$props.tableOptions.tableName,
          id:cloneItem.id,
          delFlag:this.$props.tableOptions.delFlagNum || '2'
        }
        onlineDel(this.$props.tableOptions.delUrl,params).then(res => {
          if(res.code == 200){
            this.$message.success('删除成功')
            this.getTableList()
          }
          else{
            this.$message.error(res.msg || '删除失败')
          }
        })
      })
    },
    saveForm(){
      if(!this.formConfig.popUpMode || this.formConfig.popUpMode == '正常布局'){
        this.$refs.vFormCurrentRowRef.getFormData().then(res => {
          const resKeys = Object.keys(res)
          for(let key of resKeys){
            if(Array.isArray(res[key])){
              res[key] = res[key].join(',')
              continue
            }
            else{
              continue
            }
          }
          console.log(res,'res-res-1')
          const data = {
            ...res,
            tableName:this.$props.tableOptions.tableName
          }
          if(this.scopeData.hasOwnProperty('susceptibility_results') && this.scopeData.susceptibility_results){
            data.susceptibility_results = JSON.stringify(this.scopeData.susceptibility_results)
          }
          if(this.saveType == 1){
            data.id = this.saveId
            onlineEdit(this.$props.tableOptions.editUrl,data).then(result => {
              if(result.code == 200){
                this.$message.success('编辑成功')
                this.getTableList()
                this.showInput = false
              }
              else{
                this.$message.error(res.msg || '编辑失败')
              }
            })
          }
          else if(!this.saveType){
            onlineAdd(this.$props.tableOptions.addUrl,data).then(result => {
              if(result.code == 200){
                this.$message.success('保存成功')
                this.paging.currentPage = 1
                this.getTableList()
                this.showInput = false
              }
              else{
                this.$message.error(res.msg || '保存失败')
              }
            })
          }

        })
      }
      else if(this.formConfig.popUpMode == '对话框'){
        this.$refs.dialogRowRef.getFormData().then(res => {
          const resKeys = Object.keys(res)
          for(let key of resKeys){
            if(Array.isArray(res[key])){
              res[key] = res[key].join(',')
              continue
            }
            else{
              continue
            }
          }
          const data = {
            ...res,
            tableName:this.$props.tableOptions.tableName
          }
          if(this.scopeData.hasOwnProperty('susceptibility_results' && this.scopeData.susceptibility_results)){
            data.susceptibility_results = JSON.stringify(this.scopeData.susceptibility_results)
          }
          if(this.saveType == 1){
            data.id = this.saveId
            onlineEdit(this.$props.tableOptions.editUrl,data).then(result => {
              if(result.code == 200){
                this.$message.success('编辑成功')
                this.getTableList()
                this.showInput = false
                this.$refs.refDialog1.closeDialog()
              }
              else{
                this.$message.error(res.msg || '编辑失败')
              }
            })
          }
          else if(!this.saveType){
            onlineAdd(this.$props.tableOptions.addUrl,data).then(result => {
              if(result.code == 200){
                this.$message.success('保存成功')
                this.paging.currentPage = 1
                this.getTableList()
                this.showInput = false
                this.$refs.refDialog1.closeDialog()
              }
              else{
                this.$message.error(res.msg || '保存失败')
              }
            })
          }

        })
      }
      else if(this.formConfig.popUpMode == '抽屉'){
        this.$refs.drawerRowRef.getFormData().then(res => {
          const resKeys = Object.keys(res)
          for(let key of resKeys){
            if(Array.isArray(res[key])){
              res[key] = res[key].join(',')
              continue
            }
            else{
              continue
            }
          }
          const data = {
            ...res,
            tableName:this.$props.tableOptions.tableName
          }
          if(this.scopeData.hasOwnProperty('susceptibility_results') && this.scopeData.susceptibility_results){
            data.susceptibility_results = JSON.stringify(this.scopeData.susceptibility_results)
          }
          if(this.saveType == 1){
            data.id = this.saveId
            onlineEdit(this.$props.tableOptions.editUrl,data).then(result => {
              if(result.code == 200){
                this.$message.success('编辑成功')
                this.getTableList()
                this.showInput = false
                this.$refs.refDrawer1.closeDrawer()
              }
              else{
                this.$message.error(res.msg || '编辑失败')
              }
            })
          }
          else if(!this.saveType){
            onlineAdd(this.$props.tableOptions.addUrl,data).then(result => {
              if(result.code == 200){
                this.$message.success('保存成功')
                this.paging.currentPage = 1
                this.getTableList()
                this.showInput = false
                this.$refs.refDrawer1.closeDrawer()
              }
              else{
                this.$message.error(res.msg || '保存失败')
              }
            })
          }

        })
      }
    },
    submitDialog(){
      this.$refs.vFormDialogRowRef.getFormData().then(res => {
        console.log(res,'res')
        const resKeys = Object.keys(res)
        for(let key of resKeys){
          if(Array.isArray(res[key])){
            res[key] = res[key].join(',')
            continue
          }
          else{
            continue
          }
        }
        this.$refs.refDialog.closeDialog()
      })

    },
    submitDrawer(){
      this.$refs.vFormDrawerRowRef.getFormData().then(res => {
        console.log(res,'res')
        const resKeys = Object.keys(res)
        for(let key of resKeys){
          if(Array.isArray(res[key])){
            res[key] = res[key].join(',')
            continue
          }
          else{
            continue
          }
        }
        this.$refs.refDrawer.closeDrawer()
      })
    },
    branchFormDialog(row,scopeRow){
      if(row.mode == '表单'){
        if(row.formInteraction == '对话框'){
          this.dialogTitle = row.title
          this.$refs.refDialog.throwOpenDialog()

          this.$nextTick(()=>{ //设置表单
            this.$refs.vFormDialogRowRef.setFormJson(JSON.parse(row.formDesign))
          })
        }
        else if(row.formInteraction == '抽屉'){
          this.drawerTitle = row.title
          this.$refs.refDrawer.openDrawer()
          this.$nextTick(()=>{ //设置表单
            this.$refs.vFormDrawerRowRef.setFormJson(JSON.parse(row.formDesign))
          })
        }
        this.formDesign = row.formDesign
      }
      else if(row.mode == '确认框'){
        this.$confirm(row.rowInfo, '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          //确认逻辑
        })
      }
      else if(row.mode == '确认输入框'){
        this.$prompt(row.rowInfo, '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
        }).then(({ value }) => {
          //点击了确认
        })
      }

      else{
        let obj = null
        //自定义
        if(!scopeRow['recruitment_module&inter_result']){
          this.showInput = true
          this.disabledVal = false
          this.saveId = scopeRow['recruitment_module&id']
          this.saveType = 1
          obj = this.$props.tableOptions.chuMethod(this,this.throwFormJson)
        }
        else{
          this.showInput = true
          this.disabledVal = false
          this.saveId = scopeRow['recruitment_module&id']
          this.saveType = 1
          obj = this.$props.tableOptions.fuMethod(this,this.throwFormJson)
        }
        chaEditView({
          tableName:this.$props.tableOptions.tableName,
          id:scopeRow['recruitment_module&id']
        }).then(res => {
          if(res.code == 200){
            if(this.$props.tableOptions.hasOwnProperty('arrayKey')){
              for(let mutKey of this.$props.tableOptions.arrayKey){
                res.data[mutKey] = res.data[mutKey] && res.data[mutKey].length ? res.data[mutKey].split(',') : []
              }
            }
            this.$nextTick(()=>{
              this.$refs.vFormCurrentRowRef.setFormJson(obj)
              setTimeout(()=>{
                //设置数据并禁用
                this.$refs.vFormCurrentRowRef.setFormData(res.data)
              },500)
            })
          }
        })
      }
    },
    btnShow(item,row){
      if(item.checkBol && !item.hiddenCondition){
        return true
      }
      if(item.hiddenCondition && item.checkBol){
        let Array = []
        let strArr = item.hiddenCondition.split(' ')
        const ind = strArr.findIndex(result => result == '&&')
        if(ind == -1){
          Array = strArr
          strArr = strArr[0].split('.')
          strArr = strArr[strArr.length - 1]
          if(row[strArr] == Array[Array.length - 1]){
            return true
          }
          else{
            if(Array[Array.length - 1].includes('空')){
              if(!row[strArr]){
                return true
              }
              else{
                return false
              }
            }
            else{
              return false
            }
          }
        }
        else{
          const startArr = strArr.slice(0,ind)
          const endArr = strArr.slice(ind + 1,strArr.length)
          let startArrKey = startArr[0].split('.')
          startArrKey = startArrKey[startArrKey.length - 1] //取出第一个字段
          let endArrKey = endArr[0].split('.')
          endArrKey = endArrKey[endArrKey.length - 1] //取出第一个字段
          if(startArr[startArr.length - 1].includes('空') || endArr[endArr.length - 1].includes('空')){
            if(startArr[startArr.length - 1].includes('空')){
              if((!row[startArrKey]) && (row[endArrKey] == endArr[endArr.length - 1])){
                return true
              }
              else{
                return false
              }
            }
            else if(endArr[endArr.length - 1].includes('空')){
              if((row[startArrKey] == startArr[startArr.length - 1]) && (!row[endArrKey])){
                return true
              }
              else{
                return false
              }
            }
          }
          else{
            if((row[startArrKey] == startArr[startArr.length - 1]) && (row[endArrKey] == endArr[endArr.length - 1])){
              return false
            }
            else{
              return true
            }
          }
        }

      }
    },
    toAst(code){
      let ast = parse(code)
      console.log(ast,'ast')
    },
    selectionChange(selection){
      this.selectSelection = selection
      this.$emit('setSelection',selection)
    },
    delDatas(){
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let key = []
        let minTableName = null
        this.selectSelection.forEach(item => {
          minTableName = this.$props.tableOptions.tableName.toLowerCase()
          key.push(item[minTableName + '&' + 'id'])
        })
        getDels({ids:key.join(','),tableName:minTableName,delFlag:
            this.$props.tableOptions.hasOwnProperty('delFlagNum') ? this.$props.tableOptions.delFlagNum : '2'}).then(res => {
          if(res.code == 200){
            this.$message.success('删除成功')
            this.getTableList()
          }
          else{
            this.$message.error(res.msg || '删除失败')
          }
        })
      })

    },
    setScopeData(data){
      this.scopeData = {
        ...data
      }
    },
    axiosGetTableList(){
      this.paging.currentPage = 1
      this.getTableList()
      this.showInput = false
    },

    exportDataAxios(){
      if(this.$props.tableOptions.hasOwnProperty('searchClae') && !this.$props.tableOptions.searchClae){
        const keys = Object.keys(this.searchParams)
        for(let key of keys){
          this.searchParams[key.split('.')[1]] = this.searchParams[key]
        }
        exportDataList(this.$props.tableOptions.exportUrl,{...this.searchParams}).then(res => {
          this.$message.success('导出成功')
          exportLocationExcel(res,this.$props.tableOptions.exportName)
        })
        return
      }
      exportDataList(this.$props.tableOptions.exportUrl,{
        tableName:this.$props.tableOptions.tableName || this.tableName,
        delFlag:this.$props.tableOptions.hasOwnProperty('delFlag') ? this.$props.tableOptions.delFlag : '0',
        ...this.searchParams
      }).then(res => {
        this.$message.success('导出成功')
        exportLocationExcel(res,this.$props.tableOptions.exportName)
      })
    },
    importData(){
      if(this.$props.tableOptions.hasOwnProperty('customImport') && this.$props.tableOptions.customImport){
        //自定义导入
        this.$emit('throwImport')
      }
      else{
        //低代码自定义导入
      }
    },
    deforeUpload(file){
      this.listLoading = true
      return true
    },
    uploadSuccess(response, file, fileList){
      if(response.code == 200){
        this.listLoading = false
        this.$message.success('上传成功')
        this.paging.currentPage = 1
        this.getTableList()
      }
      else{
        this.listLoading = false
        this.$message.error(response.msg || '上传失败')
      }
    },
    uploadError(err, file, fileList){
      this.listLoading = false
      this.$message.error(err || '上传失败')
    },
    getAdminToken(){
      return getToken()
    },
    downLoadTemp(){
      this.listLoading = true
      downGeneralTemp({tableName:this.tableName}).then(res => {
        this.listLoading = false
        exportLocationExcel(res,'通用导入模板')
      }).catch(()=>{
        this.listLoading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
